﻿using AutoMapper;
using D.Medicalcare.Domain.Entities;
using D.Medicalcare.ErrorCode;
using D.Medicalcare.Infrastructure.Interfaces;
using D.Medicalcare.Read.API.Application.Command.DoorSpendCommand;
using MediatR;

namespace D.Medicalcare.Read.API.Application.Handler.DoorSpendHandler
{
    /// <summary>
    /// 患者信息
    /// </summary>
    public class GetOrderIdDoorSpendHandler : IRequestHandler<GetOrderIdDoorSpendCommand, APIResult<List<DoorSpend>>>
    {

        private readonly IBaseRepository<DoorSpend> baseRepository;
        private readonly IMapper mapper;
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="baseRepository"></param>
        /// <param name="mapper"></param>
        public GetOrderIdDoorSpendHandler(IBaseRepository<DoorSpend> baseRepository, IMapper mapper)
        {
            this.baseRepository = baseRepository;
            this.mapper = mapper;
        }
        /// <summary>
        /// 获取患者信息
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task<APIResult<List<DoorSpend>>> Handle(GetOrderIdDoorSpendCommand request, CancellationToken cancellationToken)
        {
            try
            {
                APIResult<List<DoorSpend>> result = new APIResult<List<DoorSpend>>();
                result.Code = APIEnum.Mvc;
                result.Msg = "查询成功";
                var list = baseRepository.GetAll().Where(x=>x.OrderId==request.OrderId).ToList();
                result.Data = list.ToList();
               
              
                return await Task.FromResult(result);
            }
            catch (Exception)
            {

                throw;
            }
        }
    }
}
